package com.moli.iov.down.command.design.decorator.dectrators;

import com.moli.iov.down.model.dto.remoting.CommandDto;
import com.moli.iov.down.command.design.decorator.AbstractDecorator;
import com.moli.iov.down.command.design.decorator.AbstractSendCommand;
import com.moli.iov.down.command.mq.SendCache;
import com.moli.iov.util.SpringContextUtils;
import lombok.extern.slf4j.Slf4j;

/**
 * <p>
 * 添加缓存
 * </p>
 *
 * @author: zql
 * @Date: 2018/12/28 14:27
 */
@Slf4j
public class CacheDecorator extends AbstractDecorator {

    public CacheDecorator(AbstractSendCommand aSendCommand) {
        super(aSendCommand);
    }

    @Override
    public void sendCommand(CommandDto commandDto, byte[] allData) {
        try{
            SendCache sendCache = SpringContextUtils.getBean("sendCache");
            sendCache.addResultAndControlCommand(commandDto);
        }catch(Exception e){
            log.error("下发命令 添加缓存 异常", e);
        }
        super.sendCommand(commandDto, allData);
    }
}
